package com.starsea.book.ui.newpage.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.starsea.book.R
import com.starsea.book.ui.newpage.entity.FlowContentEntity
import com.starsea.book.ui.newpage.normalview.RadiusTextView
import com.starsea.book.ui.newpage.weidget.flow.FlowAdapter

/**
 * @author Lee
 * @createTime 2024-01-11 22 GMT+8
 * @desc :
 */
class CategorySortSortAdapter(var onChanged: ((value: FlowContentEntity) -> Unit)? = null) :
    FlowAdapter<FlowContentEntity>() {
    override fun getView(parent: ViewGroup?, item: FlowContentEntity, position: Int): View? {
        return LayoutInflater.from(parent!!.context).inflate(R.layout.item_category_sort, null)
    }

    override fun initView(view: View?, item: FlowContentEntity, position: Int) {
        val textView = view!!.findViewById<RadiusTextView>(R.id.rtv_content)
        textView.text = item.content

        textView.isSelected = item.isSelect
        textView.setOnClickListener { v: View? ->
            getData()?.forEach { it.isSelect = false }
            item.isSelect = true
            notifyDataChanged()
            onChanged!!.invoke(item)
        }
    }
}